package com.zc.im.common.util;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;

/**
 * Project：im
 * Date：2022/4/20
 * Time：14:31
 * Description：雪花算法工具类
 *
 * @author Challen.Zhang
 * @version 1.0
 */
public class SnowFlakeUtil {

    private static Snowflake snowflake;

    /**
     * 初始化
     *
     * @param workerId     为终端ID
     * @param dataCenterId 数据中心ID
     */
    public static void init(long workerId, long dataCenterId) {
        snowflake = IdUtil.createSnowflake(workerId, dataCenterId);
    }

    public static synchronized long snowflakeId() {
        return snowflake.nextId();
    }

    public static synchronized long snowflakeId(long workerId, long dataCenterId) {
        Snowflake snowflake = IdUtil.createSnowflake(workerId, dataCenterId);
        return snowflake.nextId();
    }

}
